﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using Dapper;
using Project.IData;
using Project.Model;

namespace Project.Data
{
    public partial class UserInfoDa 
    {
//        /// <summary>
//        /// 添加数据
//        /// </summary>
//        /// <param name="userInfo">插入数据对象</param>
//        /// <returns>数据库插入条数</returns>
//        public int Create(UserInfo userInfo)
//        {
//            string sql = @"insert into UserInfo(UserName,Age,Gender,Address,CreateTime,Phone,EmployeeId) 
//values(@UserName,@Age,@Gender,@Address,@CreateTime,@Phone,@EmployeeId)";
//            #region 参数，Dapper内部提供自动将对象解析成参数，不需要手动写；
//            //SqlParameter [] pms=new SqlParameter[]
//            //    {
//            //        new SqlParameter("Id",SqlDbType.Int), 
//            //        new SqlParameter("UserName", SqlDbType.NVarChar), 
//            //        new SqlParameter("Age",SqlDbType.Int), 
//            //        new SqlParameter("Gender",SqlDbType.SmallInt), 
//            //        new SqlParameter("Address",SqlDbType.NVarChar), 
//            //        new SqlParameter("Phone",SqlDbType.NVarChar), 
//            //        new SqlParameter("EmployeeId",SqlDbType.Int)
//            //    };
//            //pms[0].Value = userInfo.Id;
//            //pms[1].Value = userInfo.UserName;
//            //pms[2].Value = userInfo.Age;
//            //pms[3].Value = userInfo.Gender;
//            //pms[4].Value = userInfo.Address;
//            //pms[5].Value = userInfo.Phone;
//            //pms[6].Value = userInfo.EmployeeId; 
//            #endregion
//            using (var connection = MyDapper.GetSqlConnection())
//            {
//                return connection.Execute(sql, userInfo);
//            }
//        }
//        /// <summary>
//        /// 修改
//        /// </summary>
//        /// <param name="userInfo">修改数据对象</param>
//        /// <returns>修改成功条数</returns>
//        public UserInfo Edit(UserInfo userInfo)
//        {
//            string sql = @"update UserInfo set UserName = @UserName, Age = @Age, Gender = @Gender, Address = @Address, CreateTime = @CreateTime, Phone = @Phone, EmployeeId = @EmployeeId where Id = @Id";
//            using (var connection = MyDapper.GetSqlConnection())
//            {
//                connection.Execute(sql, userInfo);
//            }
//            return userInfo;
//        }
//        /// <summary>
//        /// 删除
//        /// </summary>
//        /// <param name="userInfo">用户对象，只传Id即可</param>
//        /// <returns>删除的行数</returns>
//        public int Delete(UserInfo userInfo)
//        {
//            string sql = "delete UserInfo where Id= @Id";
//            using (var connection = MyDapper.GetSqlConnection())
//            {
//                return connection.Execute(sql, userInfo);
//            }
//        }
//        /// <summary>
//        /// 获取所有的数据
//        /// </summary>
//        /// <returns></returns>
//        public List<UserInfo> LoadAllData()
//        {
//            string sql = "select Id,UserName,Age, CAST(Gender as int) as Gender,Address,CreateTime,Phone,EmployeeId from Userinfo";

//            using (var connection =MyDapper.GetSqlConnection())
//            {
//              return  connection.Query<UserInfo>(sql).ToList();
//            }
//        }
//        /// <summary>
//        /// 获取相应的分页数据
//        /// </summary>
//        /// <param name="pageIndex">第几页</param>
//        /// <param name="pageCount">每页条数</param>
//        /// <returns></returns>
//        public List<UserInfo> LoadByPage(int pageIndex, int pageCount)
//        {
//            string sql = "select Id,UserName,Age, CAST(Gender as int) as Gender,Address,CreateTime,Phone,EmployeeId from Userinfo";
//            using (var connection = MyDapper.GetSqlConnection())
//            {
//                var userList= connection.Query<UserInfo>(sql);
//                return userList.OrderBy(u => u.Id)
//                                .Skip(pageIndex*pageCount)
//                                .Take(pageCount)
//                                .Select(u => u)
//                                .ToList();
//            }
//        }
    }
}
